Prev Next |
GetItemFields returns a FieldList with the given item’s fields and corresponding values.
public override FieldList GetItemFields(
ItemDefinition item,
VersionUri version,
CallContext context
)
Sitecore calls the GetItemFields method whenever it needs to access the contents of an item, for example, when displaying the item in the Content Editor or processing the item in a rendering. Item fields are always identified via the three fields: item ID, language, and version. The method must return an instance of the FieldList class or null, if the item has no field values.
The following example shows the GetItemFields method from the Hello World example.
public override FieldList GetItemFields(ItemDefinition item, VersionUri
version, CallContext context)
{
// Create the field list that we will populate and return
FieldList fields = new FieldList();
// Each field ID must match the corresponding field ID in the
// item’s template
ID titleID = new
ID("{3F3FF111-1EE3-4181-A7E8-DFC489EAB2C4}");
// Be sure to follow the appropriate standards for field
// storage, based on the data type of the field
string title = "Hello, world!";
// Add each field to the field list
fields.Add(titleID, title);
// Return the field list
return fields;
}
If desired, the data provider may derive its own custom classes from FieldList and return an instance of one of these classes in place of an instance of FieldList.
Prev Next